﻿<Window x:Class="RSSFeedReader.Views.ManageFeedsView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:vm="clr-namespace:RSSFeedReader.ViewModels;assembly=RSSFeedReader.ViewModels" 
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:converter="clr-namespace:RSSFeedReader.Converters"
        xmlns:controls="clr-namespace:RSSFeedReader.Controls;assembly=RSSFeedReader.ViewModels"
        xmlns:attached="clr-namespace:RSSFeedReader.AttachedProperties"
        Title="Manage Feeds"
        WindowStartupLocation="CenterOwner"
        ShowInTaskbar="False"
        ResizeMode="CanResizeWithGrip"
        Width="575"
        Height="440">
    <Window.Resources>
        <converter:ChannelTypeEnumConverter x:Key="ChannelTypeConverter" />
        <HierarchicalDataTemplate x:Key="ManageFeedChannelsDataTemplate"
                                  DataType="{x:Type vm:ChannelViewModel}"
                                  ItemsSource="{Binding Children}">
            <Grid Margin="0,2,0,0"
                  Width="Auto">
                <StackPanel Orientation="Horizontal"
                            Margin="0,0,0,5">
                    <Image x:Name="image"
                           Width="18"
                           Height="18"
                           Source="{Binding Path=ChannelType, Converter={StaticResource ChannelTypeConverter}}"
                           Margin="0,0,3,0" />
                    <TextBlock x:Name="_HeaderTxtBlock"
                               Margin="0,0,5,0"
                               Text="{Binding Path=Title, Mode=OneWay}"
                               Foreground="#FFFFFFFF" />
                </StackPanel>
            </Grid>
            <HierarchicalDataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}, Mode=FindAncestor}}"
                             Value="True">
                    <Setter TargetName="_HeaderTxtBlock"
                            Property="Foreground"
                            Value="#FF767676" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}, Mode=FindAncestor}}"
                             Value="True">
                    <Setter TargetName="_HeaderTxtBlock"
                            Property="Foreground"
                            Value="#FF767676" />
                </DataTrigger>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Path=IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}, Mode=FindAncestor}}"
                                   Value="True" />
                        <Condition Binding="{Binding Path=ChannelType}"
                                   Value="Folder" />
                    </MultiDataTrigger.Conditions>
                    <Setter TargetName="image"
                            Property="Source"
                            Value="pack://application:,,,/RSSFeedReader.Resources;component/Images/OpenFolder.png" />
                </MultiDataTrigger>
            </HierarchicalDataTemplate.Triggers>
        </HierarchicalDataTemplate>
    </Window.Resources>
    <Border Background="{DynamicResource BorderBackgroundOuter}"
            Opacity="{DynamicResource BorderOuterOpacity}">
        <Border Background="{DynamicResource BorderBackgroundInner}"
                BorderThickness="{DynamicResource BorderInnerThickness}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="5" />
                    <RowDefinition Height="Auto"
                                   MinHeight="26" />
                    <!--<RowDefinition Height="5" />-->
                    <!--<RowDefinition Height="25" />-->
                    <RowDefinition Height="5" />
                    <RowDefinition Height="300*" />
                    <RowDefinition Height="5" />
                    <RowDefinition Height="Auto"
                                   MinHeight="25" />
                </Grid.RowDefinitions>
                <Expander Header="Advanced" 
                          ExpandDirection="Down" 
                          IsExpanded="False">
                    <GroupBox Header="Proxy Settings">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width=".7*" />
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <CheckBox x:Name="cbEnableProxy"
                                      Content="Use a proxy server for your settings"
                                      IsChecked="{Binding IsProxyServerEnabled}"
                                      Foreground="{DynamicResource WhiteForeground}"
                                      Margin="5,0,0,5"/>
                            <Label x:Name="proxyAddressLabel"
                                   Content="Address:"
                                   Foreground="{DynamicResource WhiteForeground}"
                                   HorizontalAlignment="Left"
                                   Margin="0,0,0,10"
                                   Grid.Row="1"/>
                            <TextBox x:Name="proxyAddressTextBox"                                 
                                     Grid.Column="1"
                                     Text="{Binding Address, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                     Background="{DynamicResource TextBoxbackground}"
                                     BorderBrush="{DynamicResource TextBoxBorderBrush}"
                                     Foreground="{DynamicResource WhiteForeground}"
                                     Margin="0,0,0,10"
                                     Height="25"
                                     Width="125"
                                     HorizontalAlignment="Left"
                                     IsEnabled="{Binding ElementName=cbEnableProxy, Path=IsChecked}"
                                     Grid.Row="1"/>
                            <Label x:Name="proxyPortLabel"
                                   Grid.Column="2"
                                   Content="Port:"
                                   Foreground="{DynamicResource WhiteForeground}"
                                   HorizontalAlignment="Right"
                                   Margin="0,0,0,10"
                                   Grid.Row="1"/>
                            <TextBox x:Name="proxyPortTextBox"
                                     Grid.Column="3"
                                     Text="{Binding Port, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, TargetNullValue={x:Static sys:String.Empty}}"
                                     Background="{DynamicResource TextBoxbackground}"
                                     BorderBrush="{DynamicResource TextBoxBorderBrush}"
                                     Foreground="{DynamicResource WhiteForeground}"
                                     Height="25"
                                     Width="125"
                                     HorizontalAlignment="Left"
                                     Margin="0,0,0,10"
                                     IsEnabled="{Binding ElementName=cbEnableProxy, Path=IsChecked}"
                                     Grid.Row="1"/>
                            <Label x:Name="proxyUserNameLabel"
                                   Grid.Row="2"
                                   Content="User Name:"
                                   Foreground="{DynamicResource WhiteForeground}"
                                   HorizontalAlignment="Left"
                                   Margin="0,0,0,10"/>
                            <TextBox x:Name="userNameTextBox"
                                     Grid.Column="1"
                                     Grid.Row="2"
                                     Text="{Binding UserName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                     Background="{DynamicResource TextBoxbackground}"
                                     BorderBrush="{DynamicResource TextBoxBorderBrush}"
                                     Foreground="{DynamicResource WhiteForeground}"
                                     Height="25"
                                     Width="125"
                                     HorizontalAlignment="Right"
                                     IsEnabled="{Binding ElementName=cbEnableProxy, Path=IsChecked}"
                                     Margin="0,0,0,10"/>
                            <Label x:Name="passwordLabel"
                                   Grid.Column="2"                               
                                   Grid.Row="2"
                                   Content="Password:"
                                   Foreground="{DynamicResource WhiteForeground}"
                                   HorizontalAlignment="Right"
                                   Margin="0,0,0,10"/>
                            <PasswordBox x:Name="passwordBox"
                                         Grid.Column="3"
                                         Grid.Row="2"
                                         Background="{DynamicResource TextBoxbackground}"
                                         BorderBrush="{DynamicResource TextBoxBorderBrush}"
                                         Foreground="{DynamicResource WhiteForeground}"
                                         Margin="0,0,0,10"
                                         Height="25"
                                         Width="125"
                                         attached:PasswordHelper.Attach="True" 
                                         attached:PasswordHelper.Password="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                         HorizontalAlignment="Left"
                                         IsEnabled="{Binding ElementName=cbEnableProxy, Path=IsChecked}"/>
                            <Label x:Name="domainLabel"                               
                                   Grid.Row="3"                               
                                   Content="Domain:"
                                   Foreground="{DynamicResource WhiteForeground}"
                                   HorizontalAlignment="Left"
                                   Margin="0,0,0,0"/>
                            <TextBox x:Name="domainTextBox"
                                     Grid.Column="1"
                                     Grid.Row="3"
                                     Text="{Binding Domain, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                     Background="{DynamicResource TextBoxbackground}"
                                     BorderBrush="{DynamicResource TextBoxBorderBrush}"
                                     Foreground="{DynamicResource WhiteForeground}"
                                     Height="25"
                                     Width="125"
                                     Margin="0,0,0,0"
                                     IsEnabled="{Binding ElementName=cbEnableProxy, Path=IsChecked}"/>
                        </Grid>
                    </GroupBox>
                </Expander>
                <StackPanel Orientation="Horizontal"
                            Grid.Row="2">
                    <Label x:Name="refreshPeriodlabel"
                       Content="Refresh period (minutes):"
                       Foreground="{DynamicResource WhiteForeground}"/>
                    <TextBox Grid.Row="2"
                         x:Name="refreshPeriodTextBox"
                         Text="{Binding RefreshPeriod, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                         Background="{DynamicResource TextBoxbackground}"
                         BorderBrush="{DynamicResource TextBoxBorderBrush}"
                         Foreground="{DynamicResource WhiteForeground}"
                         Margin="0,0,5,0"
                         Height="25"
                         Width="125"/>
                </StackPanel>
                <controls:MyTreeView Grid.Row="4"
                                     ItemsSource="{Binding Path=Channels}"
                                     ItemsPanel="{DynamicResource FeedViewItemTemplate}"
                                     ItemContainerStyle="{DynamicResource TreeViewItemStyle}"
                                     ItemTemplate="{StaticResource ManageFeedChannelsDataTemplate}"
                                     AllowDrop="True" />
                <StackPanel Grid.Row="6"
                            Orientation="Horizontal">
                    <Button x:Name="addFeedButton"
                            Width="70"
                            Content="Add Feed"
                            Template="{DynamicResource GlassButton}"
                            Margin="5,0,0,0"
                            Foreground="{DynamicResource WhiteForeground}"
                            Height="25"
                            Command="{Binding AddNewFeedCommand}" />
                    <Button x:Name="newFolderButton"
                            Width="70"
                            Content="New Folder"
                            Margin="10,0,0,0"
                            Template="{DynamicResource GlassButton}"
                            Foreground="{DynamicResource WhiteForeground}"
                            Command="{Binding NewFolderCommand}" />
                    <Button x:Name="moveToFolderButton"
                            Width="97"
                            Content="Move To Folder"
                            Margin="10,0,0,0"
                            Template="{DynamicResource GlassButton}"
                            Foreground="{DynamicResource WhiteForeground}"
                            Command="{Binding MoveToFolderCommand}"
                            Height="25" />
                    <Button x:Name="deleteButton"
                            Margin="10,0,0,0"
                            Width="70"
                            Content="Delete"
                            Template="{DynamicResource GlassButton}"
                            Foreground="{DynamicResource WhiteForeground}"
                            Command="{Binding DeleteChannelCommand}"
                            Height="25" />
                    <Button x:Name="saveButton"
                            Width="70"
                            Content="Save"
                            Template="{DynamicResource GlassButton}"
                            Foreground="{DynamicResource WhiteForeground}"
                            Command="{Binding OkCommand}"
                            IsDefault="True"
                            Height="25"
                            Margin="10,0,0,0" />
                    <Button x:Name="closeButton"
                            Margin="10,0,0,0"
                            Content="Close"
                            Template="{DynamicResource GlassButton}"
                            Foreground="{DynamicResource WhiteForeground}"
                            IsCancel="True"
                            Height="25"
                            Width="70" />
                </StackPanel>
            </Grid>
        </Border>
    </Border>
</Window>
